package com.ruoyi.merchant.controller;

import com.github.pagehelper.Page;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.merchant.annotation.DictFilter;
import com.ruoyi.merchant.domain.ReportPolice;
import com.ruoyi.merchant.dto.ReportPoliceDto;
import com.ruoyi.merchant.service.AlaramService;
import com.ruoyi.merchant.service.IBaseDeviceInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName AramController
 * @Description TODO
 * @Author chenxin.ju
 * @Date 2020-07-12 10:55
 * @ProjectName juservicecloud
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/alaram")
class AlaramController extends BaseController {

    @Autowired
    private AlaramService alaramService;
    @Autowired
    private IBaseDeviceInfoService baseDeviceInfoService;



    /**
     * 查询紧急报警
     **/
    @ResponseBody
    @RequestMapping(value = "/listAlaram", method = RequestMethod.POST)
    @DictFilter(dataType = "page")
    public TableDataInfo listAlaram(@RequestBody ReportPoliceDto reportPoliceDto) {
        Page<ReportPolice> page = null;
        try{
            if(reportPoliceDto.getPage()==null){
                reportPoliceDto.setPage(new Page<ReportPolice>());
            }
            page = alaramService.listAlaram(reportPoliceDto);
        }catch (Exception e){
            log.error("listByDeviceId",e);
            return new TableDataInfo("查询紧急报警失败");
        }
        return getDataTable(page);
    }



    /**
     *  更新紧急报警
     * @Author chengxin.ju
     * @Date  2020/3/25
     * @Param [employeeDto]
     * @return ju.maiya.huo.system.entities.base.BaseResultEntity
     **/
    @DictFilter(dataType = "item")
    @RequestMapping(value = "/updateReportPolice", method = RequestMethod.POST)
    public AjaxResult updateReportPolice(@RequestBody ReportPoliceDto reportPoliceDto) {
        try{
            if(reportPoliceDto == null
                    || reportPoliceDto.getId()==null
                    || reportPoliceDto.getHandlerId() == null
                    || reportPoliceDto.getHandlerResult() == null
            ){
                return error("参数错误，id 、 handlerId  责任人 、   handlerResult  处理结果 不能为空！");
            }
            alaramService.modfiyReportPolice(reportPoliceDto);
        }catch (Exception e){
            log.error("updateReportPolice",e);
            return error("更新紧急报警失败！");
        }
        return success(reportPoliceDto);
    }






}
